Skip to content

pcan: skip controller status messages on receive - #2133

Merged
zariiii9003 merged 3 commits into
hardbyte:mainfrom
lizaolahoaglund:pcan-skip-status-messages
Nov 23, 2026
Merged

zariiii9003 merged 3 commits into
hardbyte:mainfrom
lizaolahoaglund:pcan-skip-status-messages

Conversation

@lizaolahoaglund

@lizaolahoaglund lizaolahoaglund commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

PCAN-Basic can return PCAN_ERROR_OK for a controller status notification, for example when the controller is activated. PcanBus.recv() currently turns that notification into a CAN message, even though its ID and length don't describe a CAN frame.

Skip entries marked PCAN_MESSAGE_STATUS and keep reading. The regression tests cover Classic CAN and CAN FD, including a data frame queued behind a status notification.

PCAN-Basic status frame documentation

Type of Change

  • Bug fix

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added a news fragment for towncrier.
  • PCAN regression tests passed with tox on Windows.

PCAN-Basic can return PCAN_ERROR_OK with the PCAN_MESSAGE_STATUS bit set, for example when the CAN controller is activated. The ID and length fields in a status message do not describe a CAN frame.

Skip status messages before constructing a Message. Continue reading queued frames while respecting the receive timeout.
Comment thread can/interfaces/pcan/pcan.py Outdated
if result == PCAN_ERROR_OK:
if pcan_msg.MSGTYPE & PCAN_MESSAGE_STATUS.value:
# Keep draining queued messages on a nonblocking read.
if timeout == 0 or end_time is None or time.time() < end_time:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you can remove this condition and always continue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve removed the extra timeout check. The loop now skips the status message and moves on to the next read. I originally added the check in case repeated OK status messages kept recv() running past its deadline. PEAK describes OK as a controller activation notification, so that seems unlikely in practice.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to the PR number

lizaolahoaglund and others added 2 commits November 23, 2026 09:47
Skip status messages and read the next entry. Name the news fragment after PR hardbyte#2133.

@zariiii9003 zariiii9003 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@zariiii9003
zariiii9003 merged commit a594781 into hardbyte:main Nov 23, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants